// 该函数专门给外部提供一个临时的id
import { v4 as uuidv4 } from 'uuid';

export function getUserTempId() {
  // 先查看localStorage中是否有userTempId
  const userTempId = localStorage.getItem('userTempId');
  if (userTempId) {
    //存在直接返回
    return userTempId;
  } else {
    // 如果不存在，直接生成一个然后保存在localStorage中
    const newUserTempId = uuidv4();
    localStorage.setItem('userTempId', newUserTempId);
    return newUserTempId;
  }
}

// 获取token
export function readToken() {
  return localStorage.getItem('token');
}
// 存储token
export function setToken(token) {
  return localStorage.setItem('token', token);
}
// 删除token
export function removeToken() {
  return localStorage.removeItem('token');
}
